package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    //zyc
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = managerService.findAllUsers(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据id查询用户详情
     *
     * @param userId
     * @return
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity findUserById(@PathVariable("userId") Long userId) {
        UserInfo userInfo = managerService.findUserById(userId);
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 查询指定用户发布的所有视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid ) {
        PageResult result = managerService.findAllVideos(page,pagesize,uid);
        return ResponseEntity.ok(result);
    }

    //查询动态
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,Integer state) {
        PageResult result = managerService.findAllMovements(page,pagesize,uid,state);
        return ResponseEntity.ok(result);
    }

    //用户冻结
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map params) {
        Map map =  managerService.userFreeze(params);
        return ResponseEntity.ok(map);
    }

    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody  Map params) {
        Map map =  managerService.userUnfreeze(params);
        return ResponseEntity.ok(map);
    }

    //动态通过
    @PostMapping("/messages/pass")
    public ResponseEntity pass(@RequestBody String[] params) {
        List<String> list = new ArrayList<>();
        for (String param : params) {
           list.add(param);
        }
        return managerService.userpass(list);
    }
    //动态拒绝
    @PostMapping("/messages/reject")
    public ResponseEntity reject(@RequestBody String[] params) {
        List<String> list = new ArrayList<>();
        for (String param : params) {
            list.add(param);
        }
        return managerService.userreject(list);
    }
    //分页查询评理列表
    @GetMapping("/messages/comments")
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String messageID) {
        PageResult pr = managerService.findComments(page,pagesize,messageID);
        return ResponseEntity.ok(pr);
    }
    /**
     * 动态详情
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity findById(@PathVariable("id") String messagesId) {
        MovementsVo vo = managerService.findMovementById(messagesId);
        return ResponseEntity.ok(vo);
    }
    @PostMapping("/messages/{id}/top")
    public ResponseEntity top(@PathVariable String id) {
        String message = managerService.selectTop(id);
        return ResponseEntity.ok(message);
    }
}
